package main.leetcode.offer.secondround.from03to50;

/** 63.股票的最大利润 */
public class ex63 {
    public int maxProfit(int[] prices) {
        if (prices == null || prices.length == 0) {
            return 0;
        }
        int n = prices.length;
        int min = prices[0];
        int res = 0;
        for (int i = 1; i < n; ++i) {
            if (prices[i] < min) {
                min = prices[i];
            } else {
                res = Math.max(res, prices[i] - min);
            }
        }
        return res;
    }
}
